package com.ruoyi.web.controller.emergencyplan;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.emergencyplan.domain.EpDrillRecord;
import com.ruoyi.emergencyplan.service.IEpDrillRecordService;
import com.ruoyi.emergencyplan.vo.EpDrillRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应急预案——应急演练记录Controller
 * 
 * @author hcc
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/emergencyplan/record")
public class EpDrillRecordController extends BaseController
{
    @Autowired
    private IEpDrillRecordService epDrillRecordService;

    /**
     * 查询应急预案——应急演练记录列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpDrillRecordVo vo)
    {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EpDrillRecord> list = epDrillRecordService.selectEpDrillRecordList(vo);
        return getDataTable(list);
    }

    /**
     * 导出应急预案——应急演练记录列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:record:export')")
    @Log(title = "应急预案——应急演练记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpDrillRecord epDrillRecord)
    {
        List<EpDrillRecord> list = epDrillRecordService.selectEpDrillRecordList(epDrillRecord);
        ExcelUtil<EpDrillRecord> util = new ExcelUtil<EpDrillRecord>(EpDrillRecord.class);
        util.exportExcel(response, list, "应急预案——应急演练记录数据");
    }

    /**
     * 获取应急预案——应急演练记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(epDrillRecordService.selectEpDrillRecordById(id));
    }

    /**
     * 新增应急预案——应急演练记录
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:record:add')")
    @Log(title = "应急预案——应急演练记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpDrillRecord epDrillRecord)
    {
        epDrillRecord.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(epDrillRecordService.insertEpDrillRecord(epDrillRecord));
    }

    /**
     * 修改应急预案——应急演练记录
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:record:edit')")
    @Log(title = "应急预案——应急演练记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpDrillRecord epDrillRecord)
    {
        return toAjax(epDrillRecordService.updateEpDrillRecord(epDrillRecord));
    }

    /**
     * 删除应急预案——应急演练记录
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:record:remove')")
    @Log(title = "应急预案——应急演练记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(epDrillRecordService.deleteEpDrillRecordByIds(ids));
    }
}
